Skip to content

Don't re-trigger twice Java validation when a Java file is saved.#500

Closed
angelozerr wants to merge 1 commit into
masterfrom
properties_changed_on_jdt_improve
Closed

Don't re-trigger twice Java validation when a Java file is saved.#500
angelozerr wants to merge 1 commit into
masterfrom
properties_changed_on_jdt_improve

Conversation

@angelozerr
Copy link
Copy Markdown
Contributor

@angelozerr angelozerr commented May 14, 2025

Don't re-trigger twice Java validation when a Java file is saved.

This PR avoid sending (type=3 which means configFile changed)

[Trace - 9:33:16 PM] Sending notification 'microprofile/propertiesChanged'.
Params: {
    "type": [
        3
    ],
    "projectURIs": [
        "C:\\Users\\azerr\\Downloads\\demo\\demo"
    ]
}

which retriggers validation of Java files when a Java file is saved.

See redhat-developer/vscode-quarkus#1004 (comment)

@angelozerr angelozerr added this to the 0.14.2 milestone May 14, 2025
@angelozerr angelozerr self-assigned this May 14, 2025
@angelozerr angelozerr added the bug Something isn't working label May 14, 2025
@rgrunber rgrunber self-requested a review May 14, 2025 20:04
@angelozerr angelozerr force-pushed the properties_changed_on_jdt_improve branch 3 times, most recently from c1c1a36 to 9cf25a0 Compare May 15, 2025 04:32
file is saved.

Signed-off-by: azerr <azerr@redhat.com>
@angelozerr angelozerr force-pushed the properties_changed_on_jdt_improve branch from 9cf25a0 to ec88978 Compare May 15, 2025 14:59
@datho7561 datho7561 self-requested a review May 15, 2025 15:15
Copy link
Copy Markdown
Contributor

@datho7561 datho7561 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works great and the code changes look good. I'd like to hear from Roland as well, but I think it's a good idea to merge this.

@angelozerr
Copy link
Copy Markdown
Contributor Author

This works great and the code changes look good. I'd like to hear from Roland as well, but I think it's a good idea to merge this.

Great! Thanks @datho7561 for your feedback.

Copy link
Copy Markdown
Contributor

@rgrunber rgrunber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely fixes the properties changed notifications. Just noticed one behaviour change we should be aware of. Is this ok ?


// validate all opened java files which belong to a MicroProfile project
triggerValidationForAll(null);
// triggerValidationForAll(null);
Copy link
Copy Markdown
Contributor

@rgrunber rgrunber May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this breaks the following behaviour. You have a Java source file that defines configuration properties used in the configuration file. If those are added/removed, it affects some diagnostics :

Without this change

Screencast.From.2025-05-16.12-36-34.mp4

With this change

Screencast.From.2025-05-16.12-43-30.mp4

The diagnostics will not update when saving the config file, but they do update when continuing to type in the source file, or re-opening it. Are we ok with that ?

vscode-java does have a setting that causes this exact behaviour by default (ie. don't update opened document diagnostics when another source file being modified affects it). Mainly for performance gains.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember that I had the similar problem with IJ Quarkus.

I am pretty sure that if you save your application.properties a second time, it will work.

If it that it is because we load in cache properties (for checking validation on Java file) from the /target/application.properties and not from src/main/resources/application.properties.

I think we should load cache from src/main/resources/application.properties.

We will loose the computed variable from maven for instance declared in teh properties file, but I have never seen this usecase.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saving a second time will not fix this. Validation isn't triggered. You either need to type, or re-open the file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's strange it is working for me?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you making changes and then saving or just hitting "Save" on an unchanged file ? Making changes will update the diagnostics but saving doesn't. Where would the validation come from when triggerValidationForAll is removed from didSave above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you making changes and then saving or just hitting "Save" on an unchanged file ? Making changes will update the diagnostics but saving doesn't. Where would the validation come from when triggerValidationForAll is removed from didSave above.

Type a space and szve it twice.

I need to investigate more a proper fix.

Copy link
Copy Markdown
Contributor

@rgrunber rgrunber May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typing a space in the Java source file even without saving the file will update the diagnostics. Look at the video under "With this change" above! You can see just typing updates the diagnostics so that's fine. What I mean is that saving a file that has no changes doesn't update the diagnostics.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I mean tyep a space and save application.properried and do that twice.

It should update java diagnostics correctly, right?

Copy link
Copy Markdown
Contributor

@rgrunber rgrunber May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it does work. Interesting.

Update: I mean for the first save, the MP LS responds with no diagnostics, but on the second save it returns the diagnostic(s). I guess it can't save + return the updates diagnostics at the same time ? I guess that's fine for now.

@angelozerr all that's left is to address my comment at #500 (review)


// Exclude resources in the main output location (e.g.,/ProjectName/bin)
IPath outputLocation = javaProject.getOutputLocation();
IPath outputFullPath = ResourcesPlugin.getWorkspace().getRoot().getFolder(outputLocation).getFullPath();
Copy link
Copy Markdown
Contributor

@rgrunber rgrunber May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the full path.

image

You could compute the path relative to the workspace, in which case I don't think you need outputFullPath. you can do outputLocation.isPrefixOf(resourcePath).

If you want the absolute path on the filesystem, why not do something like javaProject.getProject().getLocation().append(outputLocation) which should be the absolute path. I've seen it used in some other places.

@datho7561 datho7561 modified the milestones: 0.15.0, 0.15.1 Dec 5, 2025
@datho7561 datho7561 modified the milestones: 0.16.0, 0.16.1 Dec 16, 2025
@angelozerr
Copy link
Copy Markdown
Contributor Author

I close this PR in favor of #546

@angelozerr angelozerr closed this Apr 21, 2026
@angelozerr angelozerr removed this from the 0.16.1 milestone Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants